
package com.limoilux.cobolux.ui.wizards;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import com.limoilux.cobolux.core.RessourceCreator;

public abstract class RessourceWizard extends Wizard implements INewWizard
{
	public IWorkbench workbench = null;
	public IStructuredSelection selection = null;

	public RessourceWizard()
	{
		super();
		this.setNeedsProgressMonitor(true);

	}

	@Override
	public boolean performFinish()
	{
		RessourceCreator creator = null;
		IWizardContainer container = null;

		boolean succes = true;

		creator = this.defineCreator();

		creator.init(this.workbench, this.selection);

		try
		{
			container = this.getContainer();
			container.run(true, false, creator);
		}
		catch (InterruptedException e)
		{
			succes = false;
		}
		catch (InvocationTargetException e)
		{
			Throwable realException = e.getTargetException();
			MessageDialog.openError(getShell(), "Error", realException.getMessage());
			succes = false;
		}
		finally
		{

		}

		return succes;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection)
	{
		this.workbench = workbench;
		this.selection = selection;

	}

	public abstract RessourceCreator defineCreator();

}
